package com.example.chatchatbackend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.UserTags;
import com.example.chatchatbackend.entity.vo.request.UserTagsVO;
import com.example.chatchatbackend.service.UserTagsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */
@Slf4j
@RestController
@RequestMapping("/api/userTags")
public class UserTagsController {
    @Autowired
    private UserTagsService userTagsService;

    @GetMapping
    public RestBean<List<UserTagsVO>> getAllComment(){
        return RestBean.success(userTagsService.getAllUserTags());
    }

    @PostMapping
    public RestBean<UserTagsVO> insertAdv(@RequestBody UserTagsVO userTagsVO){
        UserTagsVO insertUserTagsVO = userTagsService.insertUserTags(userTagsVO);
        return RestBean.success(insertUserTagsVO);

    }

    @PostMapping("/list")
    public RestBean<List<UserTagsVO>> insertAdvList (@RequestBody List<UserTagsVO> userTagsVO){
        List<UserTagsVO> UserTagsList = userTagsService.insertUserTagsList(userTagsVO);
        return RestBean.success(UserTagsList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<UserTags>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(userTagsService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<UserTagsVO> updateUserTags(@RequestBody UserTagsVO userTagsVO){
        return RestBean.success(userTagsService.updateUserTags(userTagsVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        userTagsService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/ids")
    public RestBean<List<UserTagsVO>> findByIds(@RequestBody List<Integer> ids){
        List<UserTagsVO> userTagsVOList = userTagsService.findByIds(ids);
        return RestBean.success(userTagsVOList);
    }
}
